package studentinformationmanagementsystem.service.impl;

import studentinformationmanagementsystem.dao.RequiredCourseDao;
import studentinformationmanagementsystem.dao.StudentDao;
import studentinformationmanagementsystem.dao.TakeACourseDao;
import studentinformationmanagementsystem.dao.impl.*;
import studentinformationmanagementsystem.entity.*;
import studentinformationmanagementsystem.service.StudentService;
import studentinformationmanagementsystem.utils.GetMD5;
import studentinformationmanagementsystem.utils.IDUtils;
import studentinformationmanagementsystem.utils.TimeCycle;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 苗庆
 * @version 1.0
 */
public class StudenServiceImpl implements StudentService {

           StudentDao studentDao=new StudentDaoImpl();

          RequiredCourseDao requiredCourseDao = new RequiredCourseDaoImpl();

          TakeACourseDao takeACoureDao = new TakeACoureDaolmpl();
    /**
     * 登陆
     *
     * @param student
     * @return
     */
    @Override
    public Student login(Student student) {
        return studentDao.queryByUsernameAndPassword(student);
    }

    /**
     * 检查学号是否已存在
     *
     * @param student
     * @return true 学号已存在
     */
    @Override
    public boolean isExistsUsername(Student student) {
        boolean falg=false;

        Student student1 = studentDao.queryByUsername(student);

        if (student1!=null){
            falg=true;
        }

        return falg;
    }



    /**
     * 分页查询
     * @param pageNo  查询页码
     * @param pageSize  每页的记录数
     * @return
     */
    @Override
    public Page<Student> page(int pageNo, int pageSize) {
        /**
         * 当前页码:pageNo
         * 总页码:pageTotal
         * 当前页显示的数量:pageSize
         * 总记录数:pageTotalCount
         * 当前页数据:items
         */

        //访问页面的记录条数的开始行数：当前页码-1*每页展示的记录行数
        int bigin=(pageNo-1)*pageSize;


        //总记录数量
        Integer pageTotalCount=studentDao.queryForPageTotalCount();

        //总页码数量=总记录数/每页记录显示数量，然后判断是否可以被除尽，如果不能除尽，那么总的页码数量就需要+1
        Integer pageTotal=pageTotalCount/pageSize;

        if (pageTotalCount%pageSize!=0){
            pageTotal++;
        }


        //当前页码数据
        List<Student> items = studentDao.queryForPageItems(bigin, pageSize);

        Page<Student> objectPage = new Page<Student>(pageNo,pageTotal,pageSize,pageTotalCount,items);

        return objectPage;
    }


    /**
     * 添加学生信息用户
     *
     * @param student
     */
    @Override
    public int register(Student student) {
        student.setIsDelete(0);
        return studentDao.insert(student);
    }

    /**
     *  根据ID更新学生信息
     * @param student  学生对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(Student student) {
        return studentDao.update(student);
    }


    /**
     *  根据ID删除学生
     * @param student 学生ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(Student student) {
        Student student1 = queryById(student);
        student1.setIsDelete(1);


        TakeACourse takeACourse = new TakeACourse();
        takeACourse.setStudid(student1.getStudid());
        TakeACoureDaolmpl takeACoureDaolmpl = new TakeACoureDaolmpl();
        List<TakeACourse> takeACourses = takeACoureDaolmpl.queryBystudidC01(takeACourse);
        for (TakeACourse  takeACourse1:takeACourses) {
            takeACourse1.setIsDelete(1);
            int update = takeACoureDaolmpl.update(takeACourse1);
        }
        int update = update(student1);
        return update;
    }


    /**
     * 查询所有学生信息
     * @return 所有学生信息
     */
    @Override
    public List<Student> queryAll() {
        Student student = new Student();
        student.setIsDelete(0);
        return studentDao.queryAll(student);
    }

    /**
     * 根据学生ID查询学生信息
     * @param student 学生ID
     * @return 学生信息
     */
    @Override
    public Student queryById(Student student) {
        return studentDao.queryById(student);
    }



    /**
     * 学生修改自己的账号密码
     * @param student   学生对象
     * @param formerpassword  旧密码
     * @param newpassword   新密码
     * @param confirmpassword  确认的新密码
     * @return map
     *
     * 业务逻辑：
     * 1.判断当前输入的旧密码是否和学生数据库存储的密码一致
     * 2.再次判断新密码和确认新密码是否一致
     * 3.上面两条都满足就将新密码替换旧密码
     * 4。调用修改学生信息的方法
     * 5.返回判断信息
     */
    @Override
    public Map<String, String> changePassword(Student student, String formerpassword, String newpassword, String confirmpassword) {


        //定义个map用来装返回给上一级的判断信息
        Map<String,String> map=new HashMap<>();

        //1.判断当前输入的旧密码是否和学生数据库存储的密码一致

        //将输入进来的密码进行加密
        String s = GetMD5.string2MD5(formerpassword);
        String password = student.getPassword();

        if (!s.equals(password)){
            map.put("code","0");   //"输入的旧密码不正确"
            return map;
        }

        //2.判断新密码和确认新密码是否一致
        String s1 = GetMD5.string2MD5(newpassword);
        String s2 = GetMD5.string2MD5(confirmpassword);
        if (!s1.equals(s2)){
            map.put("code","1");   //"新密码两次输入的不一致"
            return map;
        }

        //3.上面两条都满足就将新密码替换旧密码
        student.setPassword(s2);

        //4.调用修改学生信息的方法
        int update = update(student);
        //判断密码是否修改成功
        if (update>=1){
            map.put("code","2");   //"修改密码成功"
            return map;
        }else { //修改密码失败
            map.put("code","3");   //修改密码失败
            return map;
        }
    }


    /**
     *
     * @param student  包括学生的学号、身份证号、手机号
     * @return
     * 业务逻辑思路：
     * 1.对身份证格式再一次进行验证
     * 2.在身份证格式正确的情况下进行调用数据库查询，查询是否可以找到这个学生对象。
     * 3.如果可以找到这个学生，那么就修改这个学生的密码为123456
     * 4.返回成功信息。
     */
    @Override
    public Map<String, String> resetPassword(Student student) {
        //定义个map用来装返回给上一级的判断信息
        Map<String,String> map=new HashMap<>();


        //1.对身份证格式再一次进行验证
        boolean idNumber = IDUtils.isIDNumber(student.getIdnumber());

        if (idNumber==false){
            map.put("code","0");   //"输入的身份证格式有误请检查后重新输入"
            return map;
        }

        //2.在身份证格式正确的情况下进行调用数据库查询，查询是否可以找到这个学生对象。
        Student student1 = studentDao.queryByStudentidAndIdnumberAndPhone(student);

        if (student1==null){

            map.put("code","1");   //"未找到该学生对象，即学号、手机号、身份证号有误"
            return map;

        }

        //3.如果可以找到这个学生，那么就修改这个学生的密码为qw123456
        student1.setPassword(GetMD5.string2MD5("qw123456"));
        int update = studentDao.update(student1);

        if (update>=1){

            map.put("code","2");   //"重置密码成功"
            return map;

        }else {

            map.put("code","3");   //重置密码失败
            return map;
        }

    }

    @Override
    public Integer queryForPageTotalCount() {
        Integer integer = studentDao.queryForPageTotalCount();
        return integer;
    }


    /**
     * @param studentDeta  查询课程的时间
     * @param studentId   查询的学生的学号
     * @return 课程表的信息
     * 1.使用学生的学号去选修课表中和和必修课表中查询学生自己的课程信息
     * 2.通过分割传进来的课程时间，来筛选复合要求的课程信息，如果复合信息，那么就将其信息找到，并且通过分析其周几上课已经几点开课分别放入不同的数组中去
     * 3.通过这些拿到的信息，去查询课程表和教师表返回其信息
     */
    @Override
    public ArrayList<String[]> selectdate(String studentDeta, String studentId) throws ParseException {

        //将传入的年份时间进行分割
        String[] split = studentDeta.split("-");



        if (split[1].equals("09")){
            split[2]="上学期";
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy");
            Date parse = fmt.parse(split[0]);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.YEAR, +1);//当前时间加上一年,即可得到了下一年开始的年份

            split[1] = fmt.format(calendar.getTime());  //设置结束年份
        }





        String studentDetas01=null;         //课程开始时间
        String studentDetas02=null;         //课程结束时间
        if (split[2].equals("上学期")){
             studentDetas01=split[0]+"-"+"09-01";
             studentDetas02=split[1]+"-"+"02-01";
        }

        if (split[2].equals("下学期")){
            studentDetas01=split[1]+"-"+"02-01";
            studentDetas02=split[1]+"-"+"08-01";
        }





        //定义七个数组，这些数组都是拿来装对应的周一至少周日的课程
        String[] course01 = new String[5];   //周一
        String[] course02 = new String[5];   //周二
        String[] course03 = new String[5];   //周三
        String[] course04 = new String[5];   //周四
        String[] course05 = new String[5];   //周五
        String[] course06 = new String[5];   //周六
        String[] course07 = new String[5];   //周末

        RequiredCourse requiredCourse = new RequiredCourse();
        requiredCourse.setStudid(Integer.valueOf(studentId));
        TakeACourse takeACourse = new TakeACourse();
        takeACourse.setStudid(Integer.valueOf(studentId));

        //1.查询选修课信息
        List<TakeACourse> takeACourses = takeACoureDao.queryBystudidC(takeACourse);


        //判断是否找到了选修课选修信息
         if (takeACourses.size()!=0){
             for (int i = 0; i <takeACourses.size() ; i++) {
                 TakeACourse takeACourse1 = takeACourses.get(i);
                 //查询临时选课班级表 ，在通过临时班级表查询教师任课表，通过教师任课表，查询课程表信息，如果查询到的课程表信息不为空的话，进行条件判断
                 TemporaryClassTable temporaryClassTable = new TemporaryClassTable();
                 temporaryClassTable.setTemporaryclasstableid(takeACourse1.getTemporaryclasstableid());

                 //查询临时选课班级表
                 TemporaryClassTableDaolmpl temporaryClassTableDaolmpl = new TemporaryClassTableDaolmpl();
                 TemporaryClassTable temporaryClassTable1 = temporaryClassTableDaolmpl.queryById(temporaryClassTable);

                 //查询教师任课表
                 TeachersSchedules teachersSchedules = new TeachersSchedules();
                 teachersSchedules.setTeachersschedulesid(temporaryClassTable1.getTeachersschedulesid());

                 TeachersSchedulesDaolmpl teachersSchedulesDaolmpl = new TeachersSchedulesDaolmpl();
                 TeachersSchedules teachersSchedules1 = teachersSchedulesDaolmpl.queryById(teachersSchedules);


                 if (teachersSchedules1!=null){
                     ClassSchedule classSchedule = new ClassSchedule();
                     classSchedule.setClassScheduleId(teachersSchedules1.getClassScheduleId());
                     ClassScheduleDaoImpl classScheduleDao = new ClassScheduleDaoImpl();
                     ClassSchedule classSchedule1 = classScheduleDao.queryById(classSchedule);



                     if (classSchedule1!=null){




                         Date studentDetas01s = TimeCycle.time1(studentDetas01);
                         Date studentDetas02s = TimeCycle.time1(studentDetas02);
                         Date CurriculumTimes = TimeCycle.time1(classSchedule1.getCurriculumTime());
                         Date CourseEndTimes = TimeCycle.time1(classSchedule1.getCourseEndTime());







                         if (CurriculumTimes.getTime()>=studentDetas01s.getTime() && CourseEndTimes.getTime()<=studentDetas02s.getTime()){
                             //接着使用教师id和课程id拿到 教师姓名和课程名称
                             Teacher teacher = new Teacher();
                             teacher.setTeacherid(classSchedule1.getTeacherId());

                             Course course = new Course();
                             course.setCourseid(classSchedule1.getCourseid());
                             //教师姓名
                             TeacherDaoImpl teacherDao = new TeacherDaoImpl();
                             Teacher teacher1 = teacherDao.queryById01(teacher);

                             //课程名称
                             CourseDaolmpl courseDaolmpl = new CourseDaolmpl();
                             Course course1 = courseDaolmpl.queryById01(course);




                             //判断是否单周
                             String SingleAndDoubleWeeks=" ";
                             if (classSchedule1.getSingleAndDoubleWeek().equals("是")){
                                 SingleAndDoubleWeeks="单周";
                             }

                             //周一
                              if (classSchedule1.getWhichDay().equals("周一")){

                                  //判断是几点的课
                                  if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                      //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                      course01[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                              "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                  }

                                  if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                      course01[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                              "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                  }

                                  if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                      course01[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                              "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                  }

                                  if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                      course01[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                              "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                  }

                                  if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                      course01[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                              "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                  }

                              }

                             //周二
                             if (classSchedule1.getWhichDay().equals("周二")){


                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course02[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course02[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course02[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course02[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course02[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周三
                             if (classSchedule1.getWhichDay().equals("周三")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course03[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course03[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course03[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course03[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course03[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周四
                             if (classSchedule1.getWhichDay().equals("周四")){


                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course04[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course04[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course04[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course04[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course04[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周五
                             if (classSchedule1.getWhichDay().equals("周五")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course05[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course05[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course05[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course05[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course05[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }
                             //周六
                             if (classSchedule1.getWhichDay().equals("周六")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course06[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course06[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course06[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course06[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course06[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                             }

                             //周天
                             if (classSchedule1.getWhichDay().equals("周末")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course07[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course07[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course07[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course07[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course07[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }
                         }

                     }

                 }

             }

         }


        //2.查询必修课信息
        List<RequiredCourse> requiredCourses = requiredCourseDao.queryBystudid(requiredCourse);



         if (requiredCourses.size()!=0){
             for (int i = 0; i <requiredCourses.size(); i++) {
                 RequiredCourse requiredCourse1 = requiredCourses.get(i);

                 //查询教师任课表
                 TeachersSchedules teachersSchedules = new TeachersSchedules();
                 teachersSchedules.setTeachersschedulesid(requiredCourse1.getTeachersschedulesid());

                 TeachersSchedulesDaolmpl teachersSchedulesDaolmpl = new TeachersSchedulesDaolmpl();
                 TeachersSchedules teachersSchedules1 = teachersSchedulesDaolmpl.queryById(teachersSchedules);


                 if (teachersSchedules1!=null){
                     ClassSchedule classSchedule = new ClassSchedule();
                     classSchedule.setClassScheduleId(teachersSchedules1.getClassScheduleId());
                     ClassScheduleDaoImpl classScheduleDao = new ClassScheduleDaoImpl();
                     ClassSchedule classSchedule1 = classScheduleDao.queryById(classSchedule);


                     if (classSchedule1!=null){

//                         SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-DD");
//                         Date studentDetas01s = fmt.parse(studentDetas01);
//                         Date studentDetas02s = fmt.parse(studentDetas02);
//                         Date CurriculumTimes = fmt.parse(classSchedule1.getCurriculumTime());
//                         Date CourseEndTimes =  fmt.parse(classSchedule1.getCourseEndTime());


                         Date studentDetas01s = TimeCycle.time1(studentDetas01);


                         Date studentDetas02s = TimeCycle.time1(studentDetas02);



                         Date CurriculumTimes = TimeCycle.time1(classSchedule1.getCurriculumTime());
                         Date CourseEndTimes = TimeCycle.time1(classSchedule1.getCourseEndTime());




                         if (CurriculumTimes.getTime()>=studentDetas01s.getTime() && CourseEndTimes.getTime()<=studentDetas02s.getTime()){


                             //接着使用教师id和课程id拿到 教师姓名和课程名称
                             Teacher teacher = new Teacher();
                             teacher.setTeacherid(classSchedule1.getTeacherId());



                             Course course = new Course();
                             course.setCourseid(classSchedule1.getCourseid());
                             //教师姓名
                             TeacherDaoImpl teacherDao = new TeacherDaoImpl();
                             Teacher teacher1 = teacherDao.queryById01(teacher);

                             //课程名称
                             CourseDaolmpl courseDaolmpl = new CourseDaolmpl();
                             Course course1 = courseDaolmpl.queryById01(course);


                             String SingleAndDoubleWeeks=" ";
                             if (classSchedule1.getSingleAndDoubleWeek().equals("是")){
                                 SingleAndDoubleWeeks="单周";
                             } //判断是否单周

                             //周一
                             if (classSchedule1.getWhichDay().equals("周一")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course01[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course01[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course01[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course01[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course01[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                             }

                             //周二
                             if (classSchedule1.getWhichDay().equals("周二")){


                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course02[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course02[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course02[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course02[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course02[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周三
                             if (classSchedule1.getWhichDay().equals("周三")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course03[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course03[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course03[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course03[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course03[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周四
                             if (classSchedule1.getWhichDay().equals("周四")){


                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course04[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course04[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course04[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course04[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course04[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }

                             //周五
                             if (classSchedule1.getWhichDay().equals("周五")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course05[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course05[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course05[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course05[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course05[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }
                             //周六
                             if (classSchedule1.getWhichDay().equals("周六")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course06[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course06[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course06[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course06[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course06[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                             }

                             //周天
                             if (classSchedule1.getWhichDay().equals("周末")){

                                 //判断是几点的课
                                 if (classSchedule1.getStartingTime().equals("8:00")){   //早上8:00
                                     //学科名称，教师姓名，上课地点，是否单周，上课持续周数
                                     course07[0]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("10:00")){   //早上10:00
                                     course07[1]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("14:00")){   //下午14:00
                                     course07[2]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("15:50")){   //下午15:50
                                     course07[3]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }

                                 if (classSchedule1.getStartingTime().equals("18:00")){   //晚上18:00
                                     course07[4]="课程："+course1.getCoursename()+"  教师:"+teacher1.getTeachername()+"   上课地点："+classSchedule1.getPlaceOfClass()+
                                             "  "+SingleAndDoubleWeeks+"   共"+classSchedule1.getTimeOfDuration()+"周";
                                 }


                             }
                         }

                     }

                 }
             }
         }

        ArrayList<String[]> listClassSchedule = new ArrayList<>();
         listClassSchedule.add(course01);
         listClassSchedule.add(course02);
         listClassSchedule.add(course03);
         listClassSchedule.add(course04);
         listClassSchedule.add(course05);
         listClassSchedule.add(course06);
         listClassSchedule.add(course07);

         return listClassSchedule;
    }


}
